package capr.model;

import java.io.IOException;
import java.net.URL;
import com.md5importer.MD5Importer;
import com.md5importer.interfaces.model.IMD5Anim;

/**
 * @author Ludwig Lienkamp
 * @author Yi Wang (Neakor)
 * 
 * load an animation with the MD5Importer-Concurrent 
 * http://md5importer.googlecode.com/svn/trunk/
 */
public class LoadMD5Animation {
	
	protected MD5Importer importer;
	protected IMD5Anim animation;
	
	/**
	 * Ludwig Lienkamp <br>
	 *
	 * load the animation with the MD5Importer of Yi Wang
	 *
	 * @param  animationName 	name of the File
	 * @return					interface on an animation
	 */
	public IMD5Anim loadAnimation(String animationName) {
		
		importer = new MD5Importer();
		
		try {
			
			//return null, if the File not found
			URL animationURL = MD5Importer.class.getClassLoader().getResource("capr/model/data/anim/" + animationName);
	
			//load the Animation
			animation = importer.loadAnim(animationURL, animationName);
			
			//??
			importer.cleanup();	
		
		} catch(IOException e) {
		
			e.printStackTrace();
		}
		
		return animation;
	}
	
}
